import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Comparator;
class  PersonSortable{
	private String name;
	private int age;
	@Override
	public String toString() {
		return name+"-"+age;
	}
	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
		
		
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}

	
}
class NameComparator implements Comparator<PersonSortable>{

	@Override
	public int compare(PersonSortable o1, PersonSortable o2) {
		// TODO Auto-generated method stub
		return o1.getName().compareTo(o2.getName());
	}
	
}
class AgeComparator implements Comparator<PersonSortable>{

	@Override
	public int compare(PersonSortable o1, PersonSortable o2) {
		// TODO Auto-generated method stub
		return o1.getAge()-o2.getAge();
	}
	
}
public class Main {
    
	public static void main(String[] args) {
		// TODO Auto-generated method stub
   Scanner in=new Scanner(System.in);
   int t=in.nextInt();
   PersonSortable[] a=new PersonSortable[t];
   for(int i=0;i<t;i++)
 { PersonSortable perpll=new PersonSortable(in.next(),in.nextInt());
   a[i]=perpll;
 }
   System.out.printf("NameComparator:sort\n");
   Arrays.sort(a,new NameComparator());
   for(int i=0;i<t;i++)
   System.out.println(a[i]);
   System.out.print("AgeComparator:sort\n");
   Arrays.sort(a,new AgeComparator());
   for(int i=0;i<t;i++)
   System.out.println(a[i]);
   System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
   System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}
	
}